<?php
include_once(dirname(__FILE__) . "/../../configure/configure.php");		//--> global var
include_once(dirname(__FILE__) . "/../configure/admin.config.inc.php");	//--> admin global var
include_once(dirname(__FILE__) ."/../tools/smarty/libs/Smarty.class.php");					//--> out template

include_once(dirname(__FILE__) ."/../../lib/impl/MerchantImpl.php");

require_once(dirname(__FILE__) . "/../controlHeader.php");				//--> system control header
require_once(dirname(__FILE__) . "/../controlOperate.php");				//-->

$merImpl 	= new MerchantImpl(DB_TAG_COUPON);		//--> Merchant

$where			= '';
$error_message 	= '';


if(isset($_GET['keyword']) && !empty($_GET['keyword'])){
	$keyword 	= $_GET['keyword'];
	$searchType = $_GET['searchType'];
	$keyword	= trim($keyword);
	
	if(empty($keyword)){
		$error_message	= 'The keyword should\'t be empty.';
	}else{
		if($searchType == 'id'){
			if(is_numeric($keyword))
				$where	= " WHERE id = $keyword";
			else
				$error_message	= 'The keyword should\'t be product ID.';
		}else if($searchType == 'name'){
			$where	= " WHERE name like '%$keyword%'";
		}else if($searchType == 'status'){
			$where	= " WHERE status like '%$keyword%'";
		}else{
			$where	= " WHERE name like '%$keyword%'";
		}
	}
}

$order = ' ORDER BY id DESC';

$arrDataList = $merImpl->getCustomArray("merchant $where", $order, $page, DISPLAY_DATA_SIZE);

$arrSearchType = array('id' => 'ID', 'name' => 'Name', 'status' => 'Status');

/*----- out html -----*/
$smarty = new Smarty();					//----- out template
$smarty->template_dir = TEMPLATE_SYS_DIR;
$smarty->compile_dir  = COMPILE_SYS_DIR;

$smarty->assign('error_message', $error_message);
$smarty->assign('menuGid', $menuGid);
$smarty->assign('menuid', $menuid);

$smarty->assign('selfFileName', $selfFileName);
$smarty->assign('arrOperateInfo', $arrOperateInfo);

$smarty->assign('arrDataList', $arrDataList);

$smarty->assign('PAGE_BAR', $merImpl->pagenav);

$smarty->assign('arrSearchType', $arrSearchType);
$smarty->assign('searchTypeS', $searchType);
$smarty->assign('keyword', $keyword);

$smarty->display('listMerchant.htm');
?>
